package cn.ytr.crm.web.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录拦截器，如果没有登录，禁止访问，自动会到登录页
 */
public class CheckLoginInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		
		//获取登录员工 session 判断 session 是否为空
		Object employee = request.getSession().getAttribute("EMP_IN_SESSION");
		if (employee == null) {
			response.sendRedirect("/login.html");
			return false;
		} else {
			//放行
			return true;
		}
		
	}
	
}
